<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/include/header.jsp"%>
<title>查询${config.beanDescription}列表</title>
</head>
<body>
	<div class="wrap">
		<!-- top start -->
		<%@ include file="/include/top.jsp"%>
		<!-- top end -->

		<div class="main">
			<!--left start-->
			<%@ include file="/include/left.jsp"%>
			<!--left end-->

			<!--right start-->
			<div class="m_right">
				<div class="switch" id="switch"></div>
				<div class="p_bar">您当前的位置：${config.beanDescription}列表</div>
				<div class="con_box m_t10 t_c" id="queryDiv">
					<!-- 查询条件 : 注意加上 data-qname -->
					<table class="c_table m_t10">
						<tr>
							<td> 行政级别编码:</td>
							<td align="left"><input type="text" data-qname="code" class="input_txt" /></td>
							<td>
								<input type="button" id="searchBtn" value="查询" class="c_btn"> 
							</td>
						</tr>
					</table> 
				</div>
				<div class="action_box m_t10 t_r pro_box">
					<input type="button" class="r_btn" value="添加" id="addBtn" />
					<table id="tbwrap" class="table_list"></table>
					<div class="page eui-pager-custom" id="j_pager"></div>
				</div>
			</div>
			<!--right end-->
			<div class="bottom_panel"></div>
		</div>
		<div class="bottom_box"></div>
	</div>
	
<script type="text/html" id="tb_template">
		<thead>
				<tr>
<#list columnList as column>
					<th>${column.dbColumnComment}</th>
</#list>
					<th>操作</th>
				</tr>
		</thead>
		<tbody data-type="body">
			<!if(list.length>0) { !>
				<!for(var i=0,len=list.length;i<len;i++){
					var item = list[i],classItem = (i%2!=0)?"odd td_odd":"even";
				!>
				<tr class="gradeA <!=classItem!>">
					<#list columnList as column>
						<td title="<!=item["${column.javaPropertyName}"]!>"><!=item["${column.javaPropertyName}"]!></td>
					</#list>
						<td>
							<input type="button"  data-value="<!=item["uuid"]!>"  value="详情" class="detail  m_r5" action="view">
							<input type="button"  data-value="<!=item["uuid"]!>"  value="修改" class="mod_btn m_r5" action="edit">
							<input type="button"  data-value="<!=item["uuid"]!>"  value="删除" class="delete_btn" action="delete">
						</td>
				</tr>
			<!}!>
			<!}else{!>
				<tr>
					<td colspan="${columnList?size+1}"> 暂无数据</td>
				</tr>
			<!}!>
		</tbody>
	</script>


	<script type="text/javascript">
		var ${simpleBeanName}Dialog;
		$(function() {

			//ajax请求添加等待图片
			$(document).ajaxStart(function() {
				ZENG.msgbox.show(" 正在加载中，请稍后...", 6, 8000);
			});

			$(document).ajaxComplete(function() {
				ZENG.msgbox.hide();
			});

			// 添加
			$("#addBtn").click(function() {
				seajs.use("component/dialog", function(dialog) {
					${simpleBeanName}Dialog = new dialog({
						"width": 800,
						"height": 500,
						"contentType": "iframe",
						"contentScroll": false,
						"html": "${ctx}/${simpleBeanName}/toAdd.do",
						"title": "添加${config.beanDescription}信息" //标题
					});
				});
			});
			
			// 详细
			$("#tbwrap").delegate("[action='view']", "click", function() {
				//获取主键
				var ${beanId} = $(this).data("value");
				// 弹窗窗口
				seajs.use("component/dialog", function(dialog) {
					${simpleBeanName}Dialog = new dialog({
						"width" : 800,
						"height" : 600,
						"contentType" : "iframe",
						"contentScroll": false,
						"html" : "${ctx}/${simpleBeanName}/view.do?${beanId}=" + ${beanId}, // 内容
						"title" : "查看${config.beanDescription}详细信息" //标题
					});
				});
			});
			
			// 编辑
			$("#tbwrap").delegate("[action='edit']", "click", function() {
				//获取主键
				var ${beanId} = $(this).data("value");
				//弹窗窗口
				seajs.use("component/dialog", function(dialog) {
					${simpleBeanName}Dialog = new dialog({
						"width": 800,
						"height": 600,
						"contentType": "iframe",
						"contentScroll": false,
						"html": "${ctx}/${simpleBeanName}/toEdit.do?${beanId}=" + ${beanId},
						"title": "编辑${config.beanDescription}详细信息" //标题
					});
				});
			});
			// 删除
			$("#tbwrap").delegate("[action='delete']", "click", function() {
				//获取主键
				var ${beanId} = $(this).data("value");
				if (confirm('确定删除？')) {
					$.post("${ctx}/${simpleBeanName}/delete.do", { ${beanId} :${beanId} , CSRFToken : $("#CSRFToken").val()}, function(result) {
						if ("succ" == result) {
							search(); 
							alert("操作成功");
						} else if ("notThroughSecurityCheck" == result["isThroughSecurityCheck"]) { // 如果不通过安全检查
							var mess = result["mess"];
							$.post("${ctx}/common/notThroughSecurityCheck.do?ts=" + new Date().getTime(), mess, function(res) {
								alert(res);
							},"json");
	
						} else {
							alert(result);
						}
					}, "json");
				}
			
			});
			// 5、查询
			$("#searchBtn").click(function() {
				search();
			});
			
			// 页面加载完成调用查询分页
			search();
		});
	</script>

	<script type="text/javascript">
		function search() {
			// 这里放包含查询条件的DIV
			var paramData = easyUtils.getQueryDivDefault("queryDiv");

			seajs.use([ "component/table" ], function(uiTable) {
				var param = {
					url : "${ctx}/${simpleBeanName}/ajaxPage.do",
					data : paramData
				};
				easyUtils.getData(param, function(result) {
					easyUtils.buildTable(result, param, uiTable);
				});
			});
		}
	</script>
	<%@ include file="/include/footer.jsp"%>
</body>
</html>
